package com.andreas.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 描述：专门与RabbitMQ获得连接
 */
public class ConnectionUtils {
    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.248.132");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/ZQ");
        connectionFactory.setUsername("zhouqian");
        connectionFactory.setPassword("123456");
        return connectionFactory.newConnection();
    }

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = getConnection();
        System.out.println("connection = " + connection);
        // connection = amqp://zhouqian@192.168.248.132:5672/
        connection.close();
    }
}
